<?php
//
//  INDEX PAGE
//

require_once('header.php');

$pub = $session->publication;
view($pub);
?>

    
    
    <section>
            
	    <div class="table-frame padding">
	        
     	     <table class="subscription-table">
    	         <thead>
                    <tr class="heading-row skin-gradient">
                        <th class=""><h1 class="section-title">PUBLICATION SETTINGS</h1></th>
                    </tr>
                </thead>
                
                <tbody>
                    <tr>
                        <td>
                            <h2><?php $pub->attr('name');?></h2>
                        </td>
                    </tr>
                    <tr>
                        <td class="align-top">
                            <form class="edit-form" method="post" action="">
                                
                            <label><span>Name:</span>
                            <input type="text" readonly value="<?php $pub->attr('name'); ?>" name="name" />
                            </label>
                            
                            <label><span>Added:</span>
                            <input type="text" readonly value="<?php echo date("F j Y", strtotime($pub->datestamp)); ?>" name="datestamp" />
                            </label>
                            
                            <label><span>Rollover Date:</span>
                            <input type="text"  value="<?php $pub->attr('week_origin'); ?>" name="week_origin" readonly />
                            <span class="show-tool-tip" title="This helps calculate your week numbers.">?</span>
                            </label>
                            
                            <label><span>Publication Day:</span>
                                <select name="publication_day">
                                    <?php for ( $i = 1; $i <= 7; $i ++ ) { ?>
                                          <option value="<?php echo $i; ?>" <?php echo ( $i == $pub->publication_day ) ? "selected" : ''?>><?php echo $weeks[$i-1]; ?></option>
                                    <?php } ?>
                                </select>
                            <span class="show-tool-tip" title="The day your publication is officially mailed out. The day after is the day your subscription management system rolls over into the next week.">?</span>
                            </label>
                            
                            <label><span>Records Per Page:</span>
                            <input type="number"  value="<?php $pub->attr('setting_records_per_page'); ?>" name="setting_records_per_page" />
                            <span class="show-tool-tip" title="Controls how many subscriptions are displayed in the main subscription area. Increasing this amount may increase loading times, please find a suitable balance.">?</span>
                            </label>
                            
                            <label><span>Notify Me of Expiring Subscriptions X Weeks Before:</span>
                            <input type="number"  value="<?php $pub->attr('setting_expiring_tolerance'); ?>" name="setting_expiring_tolerance" />
                            <span class="show-tool-tip" title="Subscriptions will be flagged as Expiring this many weeks prior to their expiration.">?</span>
                            </label>
                            
                            <label><span>Subscription Grace Period:</span>
                            <input type="number"  value="<?php $pub->attr('setting_expired_tolerance'); ?>" name="setting_expired_tolerance" />
                            <span class="show-tool-tip" title="Expired subscriptions will receive thier issues for X weeks after expiration.">?</span>
                            </label>
                            
                            </label>
                            <label><span>Local Towns:</span>
                            <textarea name="setting_local_locations"><?php $pub->attr('setting_local_locations'); ?></textarea>
                            <span class="show-tool-tip" title="Please list local towns of interest in a Comma Separated List. <em>Eg: town, town, town</em>">?</span>
                            </label>
                            
                            
                            
                            <label><span>Sort Order:</span>
                                
                                <?php 
                                $order = $pub->get_attr('setting_sort_order_array');
                                //postal_code,rr,box,street,street_address,apt
                                for( $i = 0;$i < 6; $i++ ) { ?>
                                <select name="setting_sort_order[]">
                                    <option value="postal_code" <?php echo ( $order[$i] == 'postal_code' ) ? ' selected="selected"' : ''; ?>>Postal Code</option>
                                    <option value="rr"          <?php echo ( $order[$i] == 'rr' ) ? ' selected="selected"' : ''; ?>>Rural Route</option>
                                    <option value="box"         <?php echo ( $order[$i] == 'box' ) ? ' selected="selected"' : ''; ?>>Box</option>
                                    <option value="street"      <?php echo ( $order[$i] == 'street' ) ? ' selected="selected"' : ''; ?>>Street</option>
                                    <option value="street_address" <?php echo ( $order[$i] == 'street_address' ) ? ' selected="selected"' : ''; ?>>Street #</option>
                                    <option value="apt"         <?php echo ( $order[$i] == 'apt' ) ? ' selected="selected"' : ''; ?>>Apartment</option>
                                </select>
                                <?php echo ( $i < 5 ) ? '&rsaquo;' : ''; ?>
                                <?php } ?>
                                
                            </label>
                            
                            <label><span>Province:</span>
                                <select name="setting_province">
                                <?
                                foreach ( $provinces as $key => $value ) {
                                    if ($pub->setting_province == $key) {
                                        echo '<option value="'.$key.'" default selected >'.$value.'</option>';
                                    } else {
                                        echo '<option value="'.$key.'">'.$value.'</option>';
                                    }
                                } ?>
                                </select>
                            <span class="show-tool-tip" title="The Province of origin for your publication. This setting will affect all your local/regional totals.">?</span>
                            </label>
                            
                            <label><span>Country:</span>
                                <select name="setting_country">
                                    <option value="Canada" default>Canada</option>
                                </select>
                            <span class="show-tool-tip" title="The country of origin for your Publication. This setting will affect your national/foreign totals.">?</span>
                            </label>
                            
                            <hr>
                            <label><span>Email:</span>
                            <input type="email"  value="<?php $pub->attr('setting_email'); ?>" name="setting_email" />
                            <span class="show-tool-tip" title="The email supplied here will be your admin email. Notifications and Reports will be auto-sent here. Please make sure it's valid and used actively.">?</span>
                            </label>
                            
                            <label><span>Username:</span>
                            <input type="text" readonly  value="<?php $pub->attr('username'); ?>" name="username" />
                            </label>
                            
                            <label><span>New Password:</span>
                            <input type="password"  value="" name="password1" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"/>
                            <span class="show-tool-tip" title="Passwords must match. Passwords are case sensitive.">?</span>
                            </label>
                            
                            <label><span>Confirm Password:</span>
                            <input type="password"  value="" name="password2" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"/>
                            </label>
                            
                            <input type="hidden"  value="<?php $pub->attr('publication_id'); ?>" name="publication_id" />
                            <input type="hidden"  value="<?php $pub->attr('table_name'); ?>" name="table_name" />
                            <input type="hidden"  name="action" value="update_publication" />
                                
                                <div class="right group">
                                    <input class="right primary-button skin-gradient" type="submit" name="update_publication" value="Save" />
                                    <a class="right text-button" href="<?php echo $Controller->page_url('home'); ?>" title="cancel new subscription">Cancel</a>
                                </div>       
                        </form>
                        </td>
                    </tr>
                    <?php
                    if( !LIVE ) {
                    ?>
                    <tr>
                        <td colspan="2">
                            <h2>Import Users</h2>
                            <p>IMPORTANT: Please paste a Comma Separated List with fields in this order: 
                                <code>FNAME</code>, <code>LNAME</code>, <code>Number</code>, <code>Street</code>, <code>RR</code>, <code>APT</code>, <code>Box</code>, <code>CITY</code>, <code>PROV</code>,  <code>POST CODE</code>, <code>TEL</code>, <code>EMAIL</code>,  <code>EXPIRES</code> 
                            </p>
                            <form class="edit-form" method="post" action="" class="group">
                                <textarea class="width-100" name="users-csv"></textarea>
                                <input type="hidden"  value="<?php $pub->attr('publication_id'); ?>" name="publication_id" />
                                <input type="hidden"  value="<?php $pub->attr('table_name'); ?>" name="table_name" />
                                <input type="hidden"  name="action" value="import_users" />
                                
                                <div class="right group">
                                    <input class="right primary-button skin-gradient" type="submit" name="submit" value="Import" />
                                </div>   
                                
                            </form>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
	    </div>
	</section>
	
<?php
//
//  End page.
//
require_once('footer.php');
?>




